package org.sxm.cloud.exception;

import org.sxm.cloud.result.ApiResultCode;

/**
 * @Description: 业务异常类
 * @Author: xmSheng
 * @Date: 2024/1/22
 */

public class BizException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private final String errorCode;

    /**
     * 异常原因
     */
    private final String reason;

    /**
     * 请求上下文
     */
    private String ctx = "";

    /**
     * 运维开始时间
     */
    private String beginTime = "";


    /**
     * 运维结束时间
     */
    private String endTime = "";

    /**
     * 请求的方法
     */
    private String method;

    /**
     * @param message
     * @param cause
     */
    public BizException(String errorCode, String message, Throwable cause, String ctx) {
        super(message, cause);
        this.errorCode = errorCode;
        this.reason = cause.getMessage();
        this.ctx = ctx;
    }

    public BizException(String errorCode, String message, Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
        this.reason = cause.getMessage();
        this.ctx = "";
    }

    /**
     * @param errorCode
     * @param message
     */
    public BizException(String errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
        this.reason = message;
    }

    public BizException(String errorCode, String message, String ctx) {
        super(message);
        this.errorCode = errorCode;
        this.reason = message;
        this.ctx = ctx;
    }

    /**
     * @param message
     * @param message
     */
    public BizException(String message, Throwable cause) {
        super(message, cause);
        this.errorCode = ApiResultCode.ERROR.getCode();
        this.reason = cause.getMessage();
    }

    /**
     * @param message
     */
    public BizException(String message) {
        super(message);
        this.errorCode = ApiResultCode.ERROR.getCode();
        this.reason = message;
    }

    /**
     * @return the errorCode
     */
    public String getErrorCode() {
        return errorCode;
    }

    /**
     * @return the reason
     */
    public String getReason() {
        return reason;
    }


    public void setCtx(String ctx) {
        this.ctx = ctx;
    }

    public String getCtx() {
        return ctx;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(String beginTime) {
        this.beginTime = beginTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }


}